package br.com.dev.tcc.model;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.content.Intent;
import br.com.dev.tcc.R;
import br.com.dev.tcc.bean.BaseItem;
import br.com.dev.tcc.builder.BaseViewItemBuilder;
import br.com.dev.tcc.constants.ExtrasConstants;
import br.com.dev.tcc.view.mapa.MapaLocais;
import br.com.dev.tcc.view.mapa.MapaMecanicasCadastradas;

public class LocaisModel {

	private Context ctx;
	private List<BaseItem> gridItens;
	private BaseViewItemBuilder builder;

	public LocaisModel(Context ctx) {

		this.ctx = ctx;
		gridItens = new ArrayList<BaseItem>();
		builder = new BaseViewItemBuilder(ctx);

		buildGridItens();
	}

	private void buildGridItens() {

		buildItemPostosCombustiveis();
		buildItemHospitais();
		buildItemPostosPolicia();
		buildItemPontosTaxi();
		buildItemMecanica();
	}

	private void buildItemPostosCombustiveis() {

		gridItens.add(builder.build(
				R.drawable.gas_station,
				R.string.locais_combustiveis,
				getMapIntent(R.string.map_service_postos_comb,
						R.string.locais_combustiveis)));
	}

	private void buildItemHospitais() {

		gridItens.add(builder.build(
				R.drawable.hosp,
				R.string.locais_hospitais,
				getMapIntent(R.string.map_service_hosp,
						R.string.locais_hospitais)));
	}

	private void buildItemPostosPolicia() {

		gridItens.add(builder.build(
				R.drawable.police,
				R.string.locais_policia,
				getMapIntent(R.string.map_service_policia,
						R.string.locais_policia)));
	}

	private void buildItemPontosTaxi() {

		gridItens.add(builder.build(R.drawable.taxi, R.string.locais_taxi,
				getMapIntent(R.string.map_service_taxi, R.string.locais_taxi)));
	}

	private void buildItemMecanica() {

		gridItens.add(builder.build(R.drawable.mech, R.string.locais_mech,
				new Intent(ctx, MapaMecanicasCadastradas.class)));
	}

	private Intent getMapIntent(int serviceStringResId, int tileStringIResd) {

		Intent it = new Intent(ctx, MapaLocais.class);
		it.putExtra(ExtrasConstants.SERVICE_TO_MAP, ctx.getResources()
				.getString(serviceStringResId));
		it.putExtra(ExtrasConstants.TITLE_TO_MAP,
				ctx.getResources().getString(tileStringIResd));

		return it;
	}

	public List<BaseItem> getGridItens() {

		return gridItens;
	}
}